package com.org.es7.controller;

import com.org.platform.model.ResultModel;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import com.org.es7.conponents.elasticsearch.EsResult;
import com.org.es7.conponents.elasticsearch.EsSearch;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @auther dh
 * @date 2021/12/18 16:21
 */
@RestController
@RequestMapping("/test")
public class TestController {


	@RequestMapping("getEsTest")
	public ResultModel getEsTest() throws Exception {

		BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
		QueryBuilder mustTypeQuery = QueryBuilders.matchQuery("TYPE", "cust_id:3");
		queryBuilder.must(mustTypeQuery);

		QueryBuilder mustNotTypeQuery = QueryBuilders.matchQuery("TYPE", "cust_type:4");
		queryBuilder.mustNot(mustNotTypeQuery);

		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		searchSourceBuilder.query(queryBuilder);

		EsResult<Map<String, Object>> esResult = EsSearch.getEsResult(searchSourceBuilder, "index_shop_test");
		return ResultModel.newSuccess(esResult);
	}

}
